import { get, post, put, del } from './request.js'

// 用户答题相关 API
export const userAnswerApi = {
  /**
   * 提交单个题目答案（一题一题地提交）
   * @param {Object} submitData - 提交的答案数据
   * @returns {Promise} 提交结果
   */
  submitSingleAnswer: (submitData) => {
    return post('/userAnswer/submitSingle', submitData, {timeout: 0})
  },

  /**
   * 获取问卷组评估结果
   * @param {string} userAnswerGroupId - 答题组ID
   * @returns {Promise} 问卷组评估结果
   */
  getGroupEvaluationResult: (userAnswerGroupId) => {
    return get(`/userAnswer/groupEvaluation/${userAnswerGroupId}`)
  },

  /**
   * 获取答题记录详情
   * @param {number} id - 答题记录ID
   * @returns {Promise} 答题记录详情
   */
  getUserAnswerDetail: (id) => {
    return get(`/userAnswer/${id}`)
  },

  /**
   * 获取答题详情列表
   * @param {number} userAnswerId - 答题记录ID
   * @returns {Promise} 答题详情列表
   */
  getUserAnswerDetailList: (userAnswerId) => {
    return get(`/userAnswer/detail/${userAnswerId}`)
  },

  /**
   * 分页查询答题记录
   * @param {Object} queryData - 查询条件
   * @returns {Promise} 分页答题记录
   */
  getUserAnswerPage: (queryData) => {
    return post('/userAnswer/page', queryData)
  },

  /**
   * 分页查询答题记录
   * @param {Object} queryData - 查询条件
   * @returns {Promise} 分页答题记录
   */
  getUserAnswerList: (queryData) => {
    return get('/userAnswer/group/list', queryData)
  },

  /**
   * 获取用户在指定问卷的最新答题记录
   * @param {number} questionnaireId - 问卷ID
   * @returns {Promise} 最新答题记录
   */
  getLatestUserAnswer: (questionnaireId) => {
    return get(`/userAnswer/latest?questionnaireId=${questionnaireId}`)
  },

  /**
   * 获取评估结果
   * @param {number} userAnswerId - 答题记录ID
   * @returns {Promise} 评估结果
   */
  getEvaluationResult: (userAnswerId) => {
    return get(`/userAnswer/evaluation/${userAnswerId}`)
  },

  /**
   * 获取多题库评估结果
   * @param {number} userAnswerGroupId - 答题组ID
   * @returns {Promise} 多题库评估结果
   */
  getMultiQuestionnaireEvaluationResult: (userAnswerGroupId) => {
    return get(`/userAnswer/evaluation/batch/${userAnswerGroupId}`)
  },
  /**
   * 下载报告
   * @param {number} userAnswerGroupId - 答题组ID
   * @param {number} userId - 用户ID
   * @returns {Promise} 下载报告
   */
  downLoadWordBatch: (userAnswerGroupId, userId) => {
    return get(`/userAnswer/downLoad-word/batch/${userAnswerGroupId}/${userId}`, {}, {responseType: 'blob'})
  },

   /**
   * 下载报告
   * @param {number} userAnswerGroupId - 答题组ID
   * @param {number} userId - 用户ID
   * @returns {Promise} 下载报告
   */
   downLoadWord: (userAnswerGroupId, userId) => {
    return get(`/userAnswer/downLoad-word/${userAnswerGroupId}/${userId}`, {}, {responseType: 'blob'})
   },
   /**
   * 导出用户答题记录
   * @param {Object} queryData - 查询条件
   * @returns {Promise} 导出用户答题记录
   */
  exportUserAnswer: (startTime, endTime) => {
    return get('/userAnswer/export', {startTime, endTime}, {responseType: 'blob', timeout: 0})
  }
}